<template>
	<div class="content">
		<image src="/static/images/login_top_bg.png" style="width: 750rpx;height: 264rpx;" mode=""></image>
		<image src="/static/images/logo-icon.png" style="width: 120rpx;" mode="widthFix"></image>
		<div style="margin: 30rpx auto;font-size: 45rpx;font-weight: 500;">
			登 录
		</div>

		<div style="padding: 60rpx;">
			<div class="inputView">
				<u-field v-model="account" icon="account" :border-bottom="false" label-width="0"
					placeholder="请填写账号/手机号">
				</u-field>
			</div>
			<div class="inputView" style="margin-top: 20rpx;">
				<u-field v-model="password" type="password" icon="lock" label-width="0" placeholder="请填写密码">
				</u-field>
			</div>
			
			<div style="margin-top: 20rpx;">
				<u-button type="primary" @click="login" shape="circle" style="height: 100rpx;">登 录</u-button>
			</div>
			<div style="margin-top: 20rpx;display: flex;justify-content: space-between;padding: 20rpx 20rpx;">
				<div>还没有账号? <span @click="goRegister" style="color: dodgerblue;"> 去注册</span> </div>
			</div>
		</div>
	</div>
</template>
<script>
	import util from '../../utils/index.js'
	import auth from '../../utils/auth.js'
	import { pub } from '../../common/event.js'
	export default { 
		data() {
			return {
				account: '',
				password: ''
			}
		},
		methods:{
			login:async function(){
				const ret = await this.$u.post(`/login/login/user`,{account:this.account,password:this.password})
				util.requestMessage({
					ret,
					message:"登录成功",
					func:function(){
						auth.setAuthorization(ret.data.token)
						auth.setRefreshAuthorization(ret.data.refreshToken)
						auth.saveUser(ret.data.user)
						pub(`loginSuccess`,ret.data)
						uni.switchTab({
							url:"/pages/index/index"
						})
					}
				})
			},
			goRegister:function(){
				uni.redirectTo({
					url:"/pages/login/register"
				})
			}
		},
		onLoad() {
			console.log(233234,auth)
		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
	}

	.inputView {
		height: 100rpx;
		background: #f1f1f1;
		border-radius: 16rpx;
		display: flex;
		align-items: center;
		border-radius: 50rpx;
	}
</style>